package net.jjjshop.front.service.lbt.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.jjjshop.common.entity.lbt.LbUserBankEntity;
import net.jjjshop.common.entity.user.User;
import net.jjjshop.framework.common.exception.BusinessException;
import net.jjjshop.framework.shiro.vo.LoginUserRedisVo;
import net.jjjshop.framework.util.LoginUtil;
import net.jjjshop.front.mapper.lbt.LbUserBankMapper;
import net.jjjshop.front.service.lbt.LbUserBankService;
import net.jjjshop.front.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("lbUserBankService")
public class LbUserBankServiceImpl extends ServiceImpl<LbUserBankMapper, LbUserBankEntity> implements LbUserBankService {

    @Autowired
    private LbUserBankMapper dao;
    @Autowired
    private UserService userService;

    @Override
    public List<LbUserBankEntity> getList(LbUserBankEntity pageParamRequest) {
        LoginUserRedisVo vo = LoginUtil.getLoginUserRedisVo();
        User user = userService.getById(vo.getUserId());
        if(user == null ){
            throw new BusinessException(-1, "未找到用户信息");
        } 
        LambdaQueryWrapper<LbUserBankEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LbUserBankEntity::getUid,vo.getUserId());
        wrapper.eq(LbUserBankEntity::getAppId,user.getAppId());
        wrapper.orderByDesc(LbUserBankEntity::getCreateTime);

        return dao.selectList(wrapper);
    }
}
